'''
Created on Oct 31, 2012

@author: petrina
'''
from link_indicator import Link_indicator
from indiutils import Indiutils
import logging

class Stddev_estimated(Link_indicator):
    '''
    calculates the standard deviation from the estimated values (regular fleet-data stored in records)
    
    unit: index value
    '''


    def __init__(self, link):
        '''        
        @param link: Link-object (containing valid records and reference) 
        '''
        
        Link_indicator.__init__(self, link)
        
        self._name = 'Standard Deviation Estimated Values'
        self._mr_name =  'stddev_estimated'
        self._unit = 'index'
        #self.unit.__doc__ = 'index value'

        self._create_title(link.id, link.direction)
        
        logging.debug("Stddev_estimated: created new Stddev_estimated")
        
    #----------------------public methods of the class-------------------------
    
    def calculate(self):
        '''
        calculates the standard deviation of estimated values
        '''
        
        logging.info("Stddev_estimated: staring to calculate the Stddev_estimated")
 
        utils = Indiutils()
        self._values = utils.calc_stddev_of(self._link.records,"speed")
        
        logging.debug("Stddev_estimated: finished calculating the Stddev_estimated")

        return self._values


#    def plot(self, plotobject):
#        Link_indicator.plot(self, plotobject)
#        
#                
#        plotobject.create_new_plot(title = "Correlation-plot", xlabel='std-observed', ylabel='std-estimated')
#        for i in range(self._intervals):
#            plotobject.plot(self._std_obs[i], self._std_est[i])     
#        plotobject.save_plot2png("corr_"+self._exp_title, 'png') 
           